﻿using System;
using System.Web.UI.WebControls;
using CvModel;
using DAL;

namespace LAB3_Cv
{
    public partial class DeletedAds : System.Web.UI.Page
    {
        private Admin _currentAdmin;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadAllDeletedAdsToList();
            }
        }
        private void LoadAllDeletedAdsToList()
        {
            _currentAdmin = Session["CurrentAdmin"] as Admin;
            
                var allAdsFromAdmin = WorkAdDB.GetAllDeletedAdsFromAdminId(_currentAdmin.AdminId);
                if (allAdsFromAdmin.Count < 1)
                {
                    LabelNoDeletedAds.Visible = true;
                }
            ListViewAds.DataSource = allAdsFromAdmin;
            ListViewAds.DataBind();
        }

        protected void ListViewAds_ItemCommand(object sender, System.Web.UI.WebControls.ListViewCommandEventArgs e)
        {
            try
            {
                var listViewItem = e.Item as ListViewItem;

                var deletedAdId = (int)ListViewAds.DataKeys[listViewItem.DataItemIndex].Value;
                Session["DeletedAd"] = deletedAdId;
                Response.Redirect("NewAd.aspx");
            }
            catch (Exception ex)
            {
                //LabelException.Text = ex.Message;
            }
        }
    }
}